package com.dek.serviceconsumer.service;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    @Value("${providerAddr}")
    private String providerAddr;

    @HystrixCommand(fallbackMethod = "helloError")
    public String hello(){
        return restTemplate.getForObject(providerAddr, String.class);
    }


    public String helloError(){
        return "oops, a error occurred!";
    }

}
